<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr1 = [1,2,3,4]
       var arr2 = [2,4,5,6]
       var arr3=[]
for(let i=0; i<arr1.length; i++){
    if(arr2.indexOf(arr1[i])>-1){
        arr3.push(arr1[i])
    }
}

console.log(arr3)
    </script>
</body>
</html>